<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>一个基于easyui的crud查询练习</title>
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/themes/color.css">
    <link rel="stylesheet" type="text/css" href="https://www.jeasyui.com/easyui/demo/demo.css">
    <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="https://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<h2>Basic CRUD Application</h2>
<p>Click the buttons on datagrid toolbar to do crud actions.</p>
<div>
    <button id="b1">jquery test button</button>
    <p id="p1"></p>
</div>
<div>
    <form action="upload" enctype="multipart/form-data" method="post">
        姓名:<input type="text" name="name"/><br/>
        文件:<input type="file" name="file"/><br/>
        <input type="submit" value="提交"/>
    </form>
</div>

<table id="dg" title="My Users" class="easyui-datagrid" style="width:1200px;height:650px"
       url="get_users"
       toolbar="#toolbar" pagination="false"
       rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="id" width="50">id</th>
        <th field="name" width="50">name</th>
        <th field="age" width="50">age</th>
        <th field="email" width="50">Email</th>
        <th field="rowVersion" width="50">rowVersion</th>
        <th field="updateTime" width="50">updateTime</th>
    </tr>
    </thead>
</table>
<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newUser()">New User</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editUser()">Edit User</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a>
</div>

<div id="dlg" class="easyui-dialog" style="width:400px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
    <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
        <h3>User Information</h3>
        <div style="margin-bottom:10px">
            <input name="id" class="easyui-textbox" required="true" label="Id:" style="width:100%">
        </div>
        <div style="margin-bottom:10px">
            <input name="name" class="easyui-textbox" required="true" label="Name:" style="width:100%">
        </div>
        <div style="margin-bottom:10px">
            <input name="age" class="easyui-textbox" label="age:" style="width:100%">
        </div>
        <div style="margin-bottom:10px">
            <input name="email" class="easyui-textbox" label="Email:" style="width:100%">
        </div>
        <div style="margin-bottom:10px">
            <input name="rowVersion" class="easyui-textbox" label="rowVersion:" style="width:100%">
        </div>
        <div style="margin-bottom:10px">
            <input name="updateTime" class="easyui-textbox" label="updateTime:" style="width:100%">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
</div>
<script type="text/javascript">
    var url;
    function newUser(){
        $('#dlg').dialog('open').dialog('center').dialog('setTitle','New User');
        $('#fm').form('clear');
        url = 'save_user';
    }
    function editUser(){
        var row = $('#dg').datagrid('getSelected');
        if (row){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit User');
            $('#fm').form('load', row);
            url = 'save_user';
        }
    }
    function saveUser(){
        $('#fm').form('submit',{
            url: url,
            iframe: false,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                if (result == "Error") {
                    $.messager.show({
                        title: 'Error',
                        msg: 'Something error!'
                    });
                } else {
                    $('#dlg').dialog('close');        // close the dialog
                    $('#dg').datagrid('reload');    // reload the user data
                }
            }
        });
    }
    function destroyUser(){
        var row = $('#dg').datagrid('getSelected');
        if (row){
            $.messager.confirm('Confirm','Are you sure you want to destroy this user?',function(r){
                if (r) {
                    $.post('remove_user', {id: row.id}, function (result) {
                        if (result == 'ok') {
                            $('#dg').datagrid('reload');    // reload the user data
                        } else {
                            $.messager.show({    // show error message
                                title: 'Error',
                                msg: result.errorMsg
                            });
                        }
                    }, 'json');
                }
            });
        }
    }
</script>
<script>
    $("#b1").click(
        function () {
            alert("I am here!")
            $.post('ajax', {}, function (result) {
                if (result.myCode == 100) {
                    alert(result.myMessage)
                } else {
                    alert(12)
                    alert(result.myCode)
                    alert(result.myMessage)

                }
            })
        })
</script>
</body>
</html>